
<?php
session_start();//在最顶端，不要bai有输出
$_SESSION['username']='username';//直接把用户名abc赋予dutest
header("content-type:text/html;charset=utf-8");
$loginSingal="";
//连接数据库
if($_SERVER["REQUEST_METHOD"]=="POST") {     //表单post提交后执行的代码，避免变量不存在的错误
   include('config.php');
    if (!$link) {
        die("连接失败: " . mysqli_connect_error());
    }
    if (isset($_POST)) {
        
        //判断验证码是否填写并且是否正确
    
            $sql = "select * from user where username = '{$_POST['username']}' ";
            $rs = mysqli_query($link, $sql); //执行sql查询
            $row = mysqli_fetch_assoc($rs);
           $sqlc = "select * from user where nicheng = '{$_POST['code']}' ";
            $rsc = mysqli_query($link, $sqlc); //执行sql查询
            $rowc = mysqli_fetch_assoc($rsc);

            if ($row || $rowc) { // 用户存在；
             
                     
                     echo 0;die;
                  
                
            } else {
                 $sql = "INSERT INTO `user`( `username`, `password`, `nicheng`) VALUES ('{$_POST['username']}','{$_POST['password']}','{$_POST['code']}')";
                          $rs = mysqli_query($link, $sql); //执行sql查询

                 echo 1;die;
             

            }
       

    }

}
?>
